package com.healthtop.web;

import com.healthtop.common.Page;
import com.healthtop.common.Views;
import com.healthtop.dto.MenuDto;
import com.healthtop.model.XsMenu;
import com.healthtop.service.DIYService;
import com.healthtop.service.XsMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/xsMenu")
public class XsMenuController {

    @Autowired
    private XsMenuService xsMenuService;

    @Autowired
    private DIYService diyService;

    // 导航列表
    @RequestMapping("/list")
    public String list(Page page){
        diyService.getMenuList(page);
        return Views.XS_MENU_LIST;
    }

    // 跳转到导航新增/编辑
    @RequestMapping("/forward")
    public String forward(MenuDto menuDto){
        xsMenuService.selectMenuById(menuDto);
        return Views.XS_MENU_FORM;
    }

    // 导航新增/编辑
    @RequestMapping("/operate")
    public String operate(MenuDto menuDto){
        xsMenuService.operateMenu(menuDto);
        return Views.REDIRECT_XS_MENU_LIST;
    }

    /**
     * 菜单删除(逻辑删除)(hyx)
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    public String delete(Long id){
        xsMenuService.delete(id);
        return Views.REDIRECT_XS_MENU_LIST;
    }

    @RequestMapping("/parentMenu")
    @ResponseBody
    public List<XsMenu> parentMenu() {
        return xsMenuService.selectParentMenu();
    }

    @RequestMapping("/getMenusByRoleId")
    @ResponseBody
    public List<Map> getMenusByRoleId(long roleId) {
        return xsMenuService.getMenusByRoleId(roleId);
    }


}
